﻿#nullable enable

using System;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using PHMEE.Controllers;
using Volo.Abp.Application.Dtos;

namespace PHMEE.EnergyEfficiency;

/// <summary>
/// 加油报告
/// </summary>
[Route("api/cbm/bunker-report")]
public class BunkerReportController : PHMEEController, IBunkerReportAppService
{
    private readonly IBunkerReportAppService _bunkerReportAppService;

    public BunkerReportController(IBunkerReportAppService bunkerReportAppService)
    {
        _bunkerReportAppService = bunkerReportAppService;
    }

    /// <summary>
    /// 检查加油量报告的时间戳是否已经存在
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="input"></param>
    /// <returns></returns>
    [Route("CheckTsExist")]
    [HttpPost]
    public Task<CheckTsExistDto> CheckTsExistAsync(Guid vesselId, CreateUpdateBunkerReportDto input)
    {
        return _bunkerReportAppService.CheckTsExistAsync(vesselId, input);
    }

    /// <summary>
    /// 获取加油量报告详情
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="ts"></param>
    /// <returns></returns>
    [Route("GetDetail")]
    [HttpGet]
    public Task<BunkerReportDto?> GetDetailAsync(Guid vesselId, DateTime ts)
    {
        return _bunkerReportAppService.GetDetailAsync(vesselId, ts);
    }

    /// <summary>
    /// 录入加油量报告
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="input"></param>
    [Route("Create")]
    [HttpPost]
    public Task CreateAsync(Guid vesselId, [Required] CreateUpdateBunkerReportDto input)
    {
        return _bunkerReportAppService.CreateAsync(vesselId, input);
    }

    /// <summary>
    /// 更新加油量报告
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="ts">旧报告的 Ts</param>
    /// <param name="input">新报告</param>
    [Route("Update")]
    [HttpPut]
    public Task UpdateAsync(Guid vesselId, DateTime ts, CreateUpdateBunkerReportDto input)
    {
        return _bunkerReportAppService.UpdateAsync(vesselId, ts, input);
    }

    /// <summary>
    /// 删除加油量报告
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="ts"></param>
    [Route("Delete")]
    [HttpDelete]
    public Task DeleteAsync(Guid vesselId, [Required] DateTime ts)
    {
        return _bunkerReportAppService.DeleteAsync(vesselId, ts);
    }

    /// <summary>
    /// 分页查询加油量报告
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="input"></param>
    /// <returns></returns>
    [Route("GetList")]
    [HttpGet]
    public Task<PagedResultDto<BunkerReportDto>> GetListAsync(Guid vesselId,
        PagedAndSortedWithTimeRangeResultRequestDto input)
    {
        return _bunkerReportAppService.GetListAsync(vesselId, input);
    }
}